<?php

namespace app\api\controller;

use app\api\model\Cache AS CacheModel;

use app\common\controller\Send;

class Cache extends Base
{
    
    
    use Send;
    /**
     * 增加个人缓存列表
     * @return array
     * @throws \think\Exception\DbException
     */
    public function addCache()
    {
        $reqData = input('');
        $return  = CacheModel::addCache($reqData);      
        return self::sendResult($return['code'], $return['data'], $return['msg']);
    }
    
    /**
     * 获取缓存列表
     * @return array
     * @throws \think\Exception\DbException
     */
    public function getCacheList()
    {
        $reqData = input('');
        $return  = CacheModel::getCacheList($reqData);
        return self::sendResult($return['code'], $return['data'], $return['msg']);
    }
    
    
    /**
     * 获取单个缓存列表
     * @return array
     * @throws \think\Exception\DbException
     */
    public function getOneCacheList()
    {
        $reqData = input('');
        $return  = CacheModel::getOneCacheList($reqData);
        return self::sendResult($return['code'], $return['data'], $return['msg']);
    }
    
    /**
     * 删除总缓存
     * @return array
     * @throws \think\Exception\DbException
     */
    public function deleteCacheList()
    {
        $reqData = input('');
        if(empty($reqData['uid']) || empty($reqData['lang_id']) || empty($reqData['class_id']) || empty($reqData['type'])){
            return self::sendResult(-1, $return['data'], '传递参数不全');
        }
        $return  = CacheModel::deleteCacheList($reqData);
        return self::sendResult($return['code'], [], $return['msg']);
    }
    
    
    /**
     * 删除单个缓存
     * @return array
     * @throws \think\Exception\DbException
     */
    public function deleteOneCacheList()
    {
        $cacheId = input('cacheId');
        $oauthId = $this->oauthInfo['id'];
        if(empty($cacheId) ){
            return self::sendResult(-1, $return['data'], '传递参数不全');
        }
        $return  = CacheModel::deleteOneCacheList($cacheId,$oauthId);
        return self::sendResult($return['code'], [], $return['msg']);
    }
    
    
    /**
     * 删除多个缓存
     * @return array
     * @throws \think\Exception\DbException
     */
    public function deleteMoreCacheList()
    {
        $cacheIds = input('cacheIds');

        if (empty($cacheIds)) {
            return self::sendResult(100,[], '参数错误');
        }

        if (!is_array($cacheIds)) {
            return self::sendResult(102,[], '参数错误');
        }

        $cacheIds = array_unique(array_filter($cacheIds));
        if (empty($cacheIds)) {
            return self::sendResult(100,[], '参数错误');
        }
        $oauthId = $this->oauthInfo['id'];
        $return  = CacheModel::deleteMoreCacheList($cacheIds,$oauthId);
        return self::sendResult($return['code'], [], $return['msg']);
    }
    
}